package ext.tianma.model;

import wt.content.FormatContentHolder;
import wt.enterprise.RevisionControlled;
import wt.folder.CabinetBased;
import wt.folder.CabinetReference;
import wt.folder.FolderEntry;
import wt.folder.Foldered;
import wt.folder.SubFolder;
import wt.iba.value.IBAHolder;
import wt.identity.DisplayIdentification;
import wt.inf.container.WTContained;
import wt.lifecycle.LifeCycleManaged;
import wt.type.TypeDefinitionInfo;
import wt.type.TypeManaged;
import wt.type.Typed;
import wt.util.LocaleIndependentMessage;
import wt.util.LocalizableMessage;
import wt.util.WTException;
import wt.viewmarkup.Viewable;

import com.ptc.windchill.annotations.metadata.DerivedProperty;
import com.ptc.windchill.annotations.metadata.ForeignKeyRole;
import com.ptc.windchill.annotations.metadata.GenAsPersistable;
import com.ptc.windchill.annotations.metadata.GeneratedForeignKey;
import com.ptc.windchill.annotations.metadata.GeneratedProperty;
import com.ptc.windchill.annotations.metadata.IconProperties;
import com.ptc.windchill.annotations.metadata.MyRole;
import com.ptc.windchill.annotations.metadata.PropertyConstraints;
import com.ptc.windchill.annotations.metadata.SupportedAPI;
import com.ptc.windchill.annotations.metadata.TableProperties;

@GenAsPersistable(superClass = RevisionControlled.class, interfaces = { WTContained.class, Typed.class, TypeManaged.class, LifeCycleManaged.class, FormatContentHolder.class, IBAHolder.class,
        DisplayIdentification.class},

properties = { @GeneratedProperty(name = "title", type = String.class, constraints = @PropertyConstraints(upperLimit = 300)),
        @GeneratedProperty(name = "description", type = String.class, constraints = @PropertyConstraints(upperLimit = 4000)) },

foreignKeys = { @GeneratedForeignKey(
        /* first defined by: Iterated */
        foreignKeyRole = @ForeignKeyRole(name = "master", type = TMObjectModelMaster.class, supportedAPI = SupportedAPI.PUBLIC, cascade = false, constraints = @PropertyConstraints(required = true)),
        myRole = @MyRole(name = "iteration", supportedAPI = SupportedAPI.PUBLIC, cascade = false)) },

derivedProperties = { @DerivedProperty(name = "number", derivedFrom = "master>number", supportedAPI = SupportedAPI.PUBLIC),
        @DerivedProperty(name = "name", derivedFrom = "master>name", supportedAPI = SupportedAPI.PUBLIC) },

tableProperties = @TableProperties(tableName = "TMObjectModel"), iconProperties = @IconProperties(
        standardIcon = "netmarkets/images/TM/TMObject.gif",
        openIcon = "netmarkets/images/TM/TMObject.gif"))
public class TMObjectModel extends _TMObjectModel {
    static final long serialVersionUID = 1; 

    public static TMObjectModel newTMObjectModel() throws WTException {
        TMObjectModel instance = new TMObjectModel();
        instance.initialize();
        return instance;
    }
    /**
     *要实现Typed接口，必须重写以下4个方法
     */
    @Override
    public String getFlexTypeIdPath() {
        return null;
    }

    @Override
    public TypeDefinitionInfo getTypeDefinitionInfo() {
        return null;
    }

    @Override
    public Object getValue() {
        return null;
    }

    @Override
    public void setValue(String arg0, String arg1) {

    }

//    /**
//     *要实现CabinetBased接口，必须重写以下4个方法(SubFolder实现该接口)
//     */
//    @Override
//    public CabinetReference getCabinetReference() {
//    	return null;
//    }
////    @Override
////    public String getName() {
////    	return null;
////    }
//    @Override
//    public String getFolderPath() {
//    	return null;
//    }
//    @Override
//    public String getLocation() {
//    	return null;
//    }
    
    public java.lang.String getNumber() {
        try {
            return (java.lang.String) ((ext.tianma.model.TMObjectModelMaster) getMaster()).getNumber();
        } catch (java.lang.NullPointerException npe) {
            return null;
        }
    }

    public void setNumber(java.lang.String number) throws wt.util.WTPropertyVetoException {
        ((ext.tianma.model.TMObjectModelMaster) getMaster()).setNumber(number);
    }

    public java.lang.String getName() {
        try {
            return (java.lang.String) ((ext.tianma.model.TMObjectModelMaster) getMaster()).getName();
        } catch (java.lang.NullPointerException npe) {
            return null;
        }
    }

    public void setName(java.lang.String name) throws wt.util.WTPropertyVetoException {
        ((ext.tianma.model.TMObjectModelMaster) getMaster()).setName(name);
    }

    @Override
    public LocalizableMessage getDisplayIdentifier() {
        StringBuilder sb = new StringBuilder();
        sb.append(getNumber());
        sb.append(",");
        sb.append(getName());
        sb.append(",");
        sb.append(getVersionIdentifier().getValue()).append(".").append(getIterationIdentifier().getValue());
        return new LocaleIndependentMessage(sb.toString());
    }

    @Override
    public String getIdentity() {
        String identity = super.getIdentity();
        StringBuilder sb = new StringBuilder();
        sb.append(getNumber());
        sb.append(",");
        sb.append(getName());
        sb.append(",");
        sb.append(getVersionIdentifier().getValue()).append(".").append(getIterationIdentifier().getValue());
        identity = identity + "-" + sb.toString();
        return identity;
    }
}
